/**
  *余额提现记录
  */
module game {

    export class TiXianJiLuMediator extends BaseMediator {
        public static NAME: string = "TiXianJiLuMediator";
        private obj;
        public constructor(viewComponent: any = null) {
            super(TiXianJiLuMediator.NAME, viewComponent);
        }

        public listNotificationInterests(): Array<any> {
            return [
                PanelNotify.HALL.STAGE_RESIZE,
                PanelNotify.HALL.OPEN_TIXIANJILU,
                PanelNotify.HALL.CLOSE_TIXIANJILU
            ];
        }
        private panel: TiXianJiLuPanel;
        public handleNotification(notification: puremvc.INotification): void {
            switch (notification.getName()) {
                case PanelNotify.HALL.STAGE_RESIZE:
                    if (this.panel) {
                        this.panel.width = GameConfig.curWidth()
                        this.panel.height = GameConfig.curHeight()
                    }
                    break;
                case PanelNotify.HALL.OPEN_TIXIANJILU: {
                    this.obj = notification.getBody();
                    this.panel = null;
                    this.panel = new TiXianJiLuPanel();
                    this.showUI(this.panel, 2, 1, true);
                    break;
                }
                case PanelNotify.HALL.CLOSE_TIXIANJILU: {
                    this.closePanel(0);
                    break;
                }
            }
        }

        /**
         * 初始化面板ui
         */
        public initUI(): void {
            this.panel.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closeButtonClick, this);
        }

        /**
         * 初始化面板数据
         */
        public initData(): void {
            var time = Math.floor(Global.getCurrTimeLong() / 1000)//这个逼接口时间是以秒做单位
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/GameWebApplication/PayGetMoneyRequest.ashx?userid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.code == 0) {
                        this.showData(obj)
                    } else {
                        Global.tipShow(obj.msg)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            request.send();
        }
        private showData(obj: any) {
            this.panel.data_group.removeChildren();
            var y = 0
            var list: Array<any> = obj["PayGetMoneyRequestCells"]
            if (list.length == 0) {
                this.panel.wushuju.visible = true;
            }
            for (var i = 0; i < list.length; i++) {

                var ConfirmTime = list[i]["RequestTime"]
                var Amount = list[i]["Amount"]
                var Status = list[i]["ChangeStatus"]


                var juhao = new eui.Label(ConfirmTime + "")
                juhao.x = 50;
                juhao.y = y + 20
                juhao.size = 18
                juhao.fontFamily = "Microsoft YaHei"
                juhao.textColor = 0xb9a49c
                this.panel.data_group.addChild(juhao)

                var name = new eui.Label(Amount / 100 + "")
                name.x = 300
                name.y = y + 20
                name.size = 18;
                name.width = 150;
                name.textAlign = "center";
                name.fontFamily = "Microsoft YaHei"
                name.textColor = 0xb9a49c
                this.panel.data_group.addChild(name)


                var xiazhu = new eui.Label(Status)
                xiazhu.x = 630
                xiazhu.y = y + 20
                xiazhu.size = 18;
                xiazhu.width = 120;
                xiazhu.textAlign = "center";
                xiazhu.fontFamily = "Microsoft YaHei"
                xiazhu.textColor = 0xb9a49c
                this.panel.data_group.addChild(xiazhu)
                y += 60
            }

        }
        private closeButtonClick(event: egret.TouchEvent): void {
            SoundManage.startAnniuBtnLoad();
            this.closePanel(1);
        }
    }
}